<%@page contentType="text/html; charset=UTF-8"%>
<%@taglib uri="/WEB-INF/struts-tags.tld" prefix="s"%>
<%@taglib uri="/WEB-INF/dianning.tld" prefix="dianning"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="zh-cn" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>设置置顶</title>
<link href="/css/infotop.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8"  src="/js/jquery-1.4.2.min.js"></script>
<script>


var selectTime = 0;
var userAmount =0;
var pageAmount = 0;

$(	function(){
	pageAmount = parseInt($("#realTime_PageAmount").val());
	selectTime = parseInt($("#realTime_FirstTimeLength").val());
	userAmount = parseInt($("#newUseramount").val());
	$("#realTime_UserAmount").html(userAmount);
	realTime_computeAmount();
	var frm = parent.$("#<s:property value="frm" escape="false"/>_<s:property value="id"/>");
	frm.css("height", "430px");
	}
)
//选择置顶类型 
function realTime_selectType(obj) {
    var type = obj.value;
    var isfull = true;
    pageAmount = 0;
  //置顶时间 
  var date = new Date();
  	var temp=0;
  	if (type == "advanced"){
  		temp=30;
  	}
    date.setDate(date.getDate() + temp);
    var year = date.getFullYear();
    var m = date.getMonth() + 1;
	var month = (m < 10) ? '0' + m : m;
	var d  = date.getDate();
	var day = (d < 10) ? '0' + d : d;
	var endtime = year+"-"+month+"-"+day;
	$("#top_endtime").html(endtime); 
    //end
    if (type == "advanced") {
    	$("#realTime_checkpagenormal").css("display","none");
    	$("#realTime_checkpageadvanced").css("display","");
    	if($("#realTime_checkpagenormal input[name='realTime_checkpage']:checked").length != 0){
    		$("#realTime_checkpagenormal input[name='realTime_checkpage']:checked").each(function(i,obj){
				$(obj).attr("checked",false);    		
    			}
    		);
    	}
    	$("#realTime_checkpageadvanced input[name='realTime_checkpage']:enabled").each(function(i,obj){
			$(obj).attr("checked",true);
			pageAmount +=parseInt(obj.value);
    		}
    	);
    	$("#advanced_timelength").css("display","");
    	$("#normal_timelength").css("display","none");
    	$("#realtime_timelength6").attr("checked",true);
    	selectTime = parseInt($("#realtime_timelength6").val());
		$("#realTime_FirstTimeLength").val(selectTime);
    } else if (type == "normal") {
        $("#realTime_checkpagenormal").css("display","");
    	$("#realTime_checkpageadvanced").css("display","none");
    	if($("#realTime_checkpageadvanced input[name='realTime_checkpage']:checked").length != 0){
    		$("#realTime_checkpageadvanced input[name='realTime_checkpage']:checked").each(function(i,obj){
				$(obj).attr("checked",false);    		
    			}
    		);
    	}
    	$("#realTime_checkpagenormal input[name='realTime_checkpage']:enabled").each(function(i,obj){
			$(obj).attr("checked",true);
			pageAmount +=parseInt(obj.value);    	
    		}
    	);
    	$("#normal_timelength").css("display","");
    	$("#advanced_timelength").css("display","none");
    	selectTime = parseInt($("#realtime_timelength6").val());
    	$("#realtime_timelength1").attr("checked",true);
    	selectTime = parseInt($("#realtime_timelength1").val());
		$("#realTime_FirstTimeLength").val(selectTime);
    }
	realTime_computeAmount();
}

//计算所需的金额
function realTime_computeAmount(){
	var allAmount = pageAmount * selectTime;
	$("#realTime_AmountCount").html(allAmount);
	if (userAmount < allAmount) {
			$("#top_pay").css("display","none")
		    $("#realTime_buzu").css("display","");
    } else {
			$("#top_pay").css("display","");
		    $("#realTime_buzu").css("display","none");
   }
}
//选择地区
function realTime_selectPage(obj){
	var sConsume = parseInt(obj.value);    
	if(obj.checked){
		pageAmount += sConsume;
	}else{
		pageAmount -= sConsume;
	}
	$("#realTime_PageAmount").val(pageAmount);
	//alert($("#realTime_PageAmount").val());
	realTime_computeAmount();
}

//选择时间
function realTime_selectTime(obj){
	var currDays=1;
	var temp = parseInt(obj.value);
	if(temp==1){
		currDays=0;
	}
	if(temp==3){
		currDays=1;
	}
	if(temp==12){
		currDays=3;
	}
	if(temp==60){
		currDays=15;
	}
	if(temp==120){
		currDays=30;
	}
	if(temp==2400){
		currDays=30;
	}
	if(temp==4800){
		currDays=60;
	}
	if(temp==7000){
		currDays=90;
	}
	if(temp==12000){
		currDays=180;
	}
	if(temp==20000){
		currDays=365;
	}
    var date = new Date();
    date.setDate(date.getDate() + currDays);
    var year = date.getFullYear();
    var m = date.getMonth() + 1;
	var month = (m < 10) ? '0' + m : m;
	var d  = date.getDate();
	var day = (d < 10) ? '0' + d : d;
	var endtime = year+"-"+month+"-"+day;
	$("#top_endtime").html(endtime);

	var timeLength = obj.value;
	timeLength = parseInt(timeLength);
	selectTime = timeLength;
	$("#realTime_FirstTimeLength").val(timeLength);
	realTime_computeAmount();
}
</script>
</head>

<body>

	<div class="mbottom">
		<div class="newzd"> 
			<div class="zdbody">
			<!-- 置顶主体开始 -->
				<div class="zdtit">
					<ul>
						<li><span><a href="info.action?action=refresh&frm=<s:property value="frm" escape="false"/>&id=<s:property value="id"/>">刷新</a></span></li>
						<li><span><a href="info.action?action=autorefresh&frm=<s:property value="frm" escape="false"/>&id=<s:property value="id"/>">定时刷新</a></span></li>
						<li class="select"><span><a href="info.action?action=top&frm=<s:property value="frm" escape="false"/>&id=<s:property value="id"/>">置顶</a></span></li>
						<li><span><a href="info.action?action=autotop&frm=<s:property value="frm" escape="false"/>&id=<s:property value="id"/>">委托置顶</a></span></li>
					</ul>
				</div>
				<div class="clear"></div>
				<div class="zdinfo">
					<div class="tjzd">
					<s:if test="message=='true'">
					<div class="yellow-b">设置成功</div>
					</s:if>	
					<s:if test="info.isCityTop==1">
					<div class="yellow-b">您己经置顶该信息</div>
					</s:if>
					<s:else>
								<table border="0" cellpadding="0" cellspacing="0" class="tjzdtable">
								<form name="top" id="top" method="post" action="info.action">
								<input name="action" id="action" type="hidden" value="dotop" />
								<input name="id" id="id" type="hidden" value="<s:property value="id"/>" />
								<input type="hidden" id="newUseramount" value="<s:property value="money.points"/>"/>
								<tr>
									<td class="tdwt">
									<input type = "radio" name="top_type" id="top_normaltype" value="normal" onclick="realTime_selectType(this)" checked="checked"/>普通置顶&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									</td>
									<td>
									<s:if test="commendNum>4">
									<input type = "radio" name="top_type" id="top_advancedtype" value="advanced"  onclick="realTime_selectType(this)" disabled="disabled"/>推广
									</s:if>
									<s:else>
									<input type = "radio" name="top_type" id="top_advancedtype" value="advanced"  onclick="realTime_selectType(this)"/>推广
									</s:else>
									<img src="/images/btn-2-new.gif"/>
								</tr>
								<tr>
									<td width="198" class="tdwt"> 选择置顶页面：</td>
									<td>
										<div id = "realTime_checkpagenormal">
											<p><input name="realTime_checkpage" checked='checked' onclick="realTime_selectPage(this)" type="checkbox" value="20"/><dianning:webinfo type="area"/>-<s:property value="info.smallChannel.channelName"/>
											<span style="color:red;font-size:14px"></span>
											</p>
											<s:if test="area!=null">
											<p><input name="realTime_checkpage" checked='checked' onclick="realTime_selectPage(this)" type="checkbox" value="1"/><s:property value="info.area.areaname"/>-<s:property value="info.smallChannel.channelName"/>
											<span style="color:red;font-size:14px"></span>
											</p>
											</s:if>
										</div>
										<div id = "realTime_checkpageadvanced" style="display:none;">
											<p><input name="realTime_checkpage"  onclick="realTime_selectPage(this)" type="checkbox" value="1"/><dianning:webinfo type="area"/>-<s:property value="info.smallChannel.channelName"/><span style="color:red;font-size:14px"></span>
											</p>
										</div>
										<s:if test="area==null">
											<input type="hidden" id="realTime_PageAmount" value="20"/>
										</s:if>
										<s:else>
											<input type="hidden" id="realTime_PageAmount" value="11"/>
										</s:else>
									</td>
								</tr>
								<tr>
									<td class="tdwt">选择置顶时长： </td> 
									<td>
									<span  id="normal_timelength">
									<input name="timelength" onclick="realTime_selectTime(this)" id="realtime_timelength1" type="radio" value="1" checked />6小时
									<input name="timelength" onclick="realTime_selectTime(this)" id="realtime_timelength2" type="radio" value="3" />16小时
									<input name="timelength" onclick="realTime_selectTime(this)" id="realtime_timelength3" type="radio" value="12" />3天
									<input name="timelength" onclick="realTime_selectTime(this)" id="realtime_timelength4" type="radio" value="60" />15天
									<input name="timelength" onclick="realTime_selectTime(this)" id="realtime_timelength5" type="radio" value="120" />30天
									</span>
									<span  id="advanced_timelength" style="display:none">
									<input name="timelength" onclick="realTime_selectTime(this)" id="realtime_timelength6" type="radio" value="2400" />30天
									<input name="timelength" onclick="realTime_selectTime(this)" id="realtime_timelength7" type="radio" value="4800" />60天
									<input name="timelength" onclick="realTime_selectTime(this)" id="realtime_timelength8" type="radio" value="7000" />90天
									<input name="timelength" onclick="realTime_selectTime(this)" id="realtime_timelength9" type="radio" value="12000" />180天
									<input name="timelength" onclick="realTime_selectTime(this)" id="realtime_timelength10" type="radio" value="20000" />365天
									</span>
									<input type="hidden" id="realTime_FirstTimeLength" value="1"/>
									</td>
								</tr>
								<tr><td class="tdwt"></td>
									<td>
									<span class="gray mr10">您选择的置顶时间为<b class="red">
									<s:date name="today" format="yyyy-MM-dd"/>
									</b>至<b class="red" id="top_endtime">
									<s:date name="today" format="yyyy-MM-dd"/>
									</span>
									</td>
								</tr>
								<tr id="realTime_textArea">
									<td colspan="2">
										<div class="yellow-b">
										<table width="100%" border="0">
										<tr>
											<td>
												此次置顶需要花费您<span class="red" id="realTime_AmountCount"></span>积分，
												<span id="realTime_tishi">您的可用余额为<span class="red" id="realTime_UserAmount"></span>积分。</span>
												<span id="realTime_buzu">余额不足</span>
											</td>
										</tr>
										</table>
										</div>
									</td>
								</tr>
								<tr>
									<td class="tdwt">&nbsp;</td>
									<td><span class="tyzdbut"  id="top_pay">
										  <label class="butt">
										  <input name="" type="submit" value="马上置顶" class="btns" />
										  </label>
									</span>
									</td>
								</tr>
							</form>
							</table>
					</div>	
			</s:else>		
			</div>
		</div>
	</div>
	
</body>
</html>